@extends('admin.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("admin.public.left")
        <aside>
            <section class="vbox">

                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="">
                        <div class="row m-t-sm">
                            <div class="col-sm-12 m-b-xs">
                                <div class="btn-group" role="group">
                                    <strong style="line-height:30px;">编辑资讯类型</strong>
                                </div>
                                <div class="btn-group pull-right">
                                    <a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
                                        <i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
                                    </a>
                                </div>
                            </div>
                        </div>
                    </form>
                </header>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default ">
                        <div class="row m-l-none m-r-none bg-light lter">
                            <div class="container" style="padding: 20px 0px">
                                <form id="formclass" class="form-horizontal" style="padding-top: 15px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">类型名称</label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="name" maxlength="4" value="{{$one->name}}"
                                                   placeholder="请输入名称">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">类型描述</label>
                                        <div class="col-sm-4 ">
                                            <textarea class="form-control" name="comment"
                                                      placeholder="请输入简介">{{$one->comment}}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">状态</label>
                                        <div class="col-sm-4">
                                            <input type="radio" id="status1" checked="checked" name="status" value="{{\App\Http\Util\Status::ON}}">
                                            <label for="status1">启用</label>
                                            <input type="radio" id="status0" name="status" value="{{\App\Http\Util\Status::OFF}}">
                                            <label for="status0">禁用</label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label"></label>
                                        <div class="col-sm-2 ">
                                            <button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
                                            <input type="checkbox" id="back">
                                            <label for="back">返回列表</label>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>

                    </section>
                </section>


            </section>
        </aside>
    </section>
@endsection
@section('addscript')
    <script>
        $(function(){
            $("#formclass").submit(function(){
                var name=$("[name=name]").val();
                var comment=$("[name=comment]").val();
                var status=$("[name=status]:checked").val();
                if(name==""){
                    layer.msg("分类名称不能为空");
                    return false;
                }
                if(comment==""){
                    layer.msg("类型描述不能为空");
                    return false;
                }
                var back=$("#back").is(':checked');
                $.ajax({
                    url:"{{ url('admin/infoType/edit/'.$one->id) }}",
                    type:"post",
                    dataType:"json",
                    data:{
                        name:name,
                        comment:comment,
                        status:status
                    },
                    success:function(data){
                        if(data.success){
                            layer.alert(data.msg,function(){
                                if (back) {
                                    location.href="{{url('admin/infoType')}}";
                                } else {
                                    location.reload();
                                }
                            });
                        }
                        else{
                            layer.alert(data.msg);
                        }
                    }
                })
                return false;
            })


        });
    </script>
@endsection
